IdeaBlade DevForce 2010 Help Reference
Start(Func<IEnumerable<INotifyCompleted>>,Action<CoroutineOperation>) Method
See Also  Example Send Feedback
IdeaBlade.EntityModel Assembly > IdeaBlade.EntityModel Namespace > Coroutine Class > Start Method : Start(Func<IEnumerable<INotifyCompleted>>,Action<CoroutineOperation>) Method



coroutine
An iterator block containing asynchronous actions
completedHandler
Optional completion handler
Start serial execution of multiple asynchronous actions.

Syntax

Visual Basic (Declaration) 
Public Overloads Shared Function Start( _
   ByVal coroutine As Func(Of IEnumerable(Of INotifyCompleted)), _
   Optional ByVal completedHandler As Action(Of CoroutineOperation) _
) As CoroutineOperation
Visual Basic (Usage)Copy Code
Dim coroutine As Func(Of IEnumerable(Of INotifyCompleted))
Dim completedHandler As Action(Of CoroutineOperation)
Dim value As CoroutineOperation
 
value = Coroutine.Start(coroutine, completedHandler)

Parameters

coroutine
An iterator block containing asynchronous actions
completedHandler
Optional completion handler

Return Value

A CoroutineOperation representing this operation

Example

C#Copy Code
public void CoroutineSample() {
   // Note that a new EM is not required for a Coroutine, we show it here for completeness.
   _mgr = new DomainModelEntityManager();
   
   // Start some serial async operations.
   var op = Coroutine.Start(SampleActions);
   
   // Listen for completion.
   op.Completed += (s, e) => {
     if (e.HasError) {
       MessageBox.Show(e.Error.Message);
       e.MarkErrorAsHandled();
     } 
   };
 }
 
 private EntityManager _mgr;

 // A block of asynchronous actions.
 private IEnumerable<INotifyCompleted> SampleActions() {

   // Start a query for all customers in specified country, yield when async op completes.
   var op1 = _mgr.Customers.Where(c => c.Country == "UK").ExecuteAsync();
   yield return op1;

   // Resume execution here when op1 completes.  Take a look at results from 1st query
   TraceFns.WriteLine("Customer count = " + op1.Results.Count().ToString());

   // Perform another async quuery for all employees.
   var op2 = _mgr.Employees.ExecuteAsync();
   yield return op2;

   // Resume execution here when op2 completes.  See what it returned.
   TraceFns.WriteLine("Employee count = " + op2.Results.Count().ToString());
 }    
 
 /***************************************************************************************/
 // Sample 2 - passing arguments to an iterator
 
 public void CoroutineSample2a() {
   // Note that a new EM is not required for a Coroutine, we show it here for completeness.
   _mgr = new DomainModelEntityManager();

   // Start some serial async operations.
   var op = Coroutine.Start(() => SampleActions2("USA"));
   
   // Listen for completion.
   op.Completed += (s, e) => {
     if (e.HasError) {
       MessageBox.Show(e.Error.Message);
       e.MarkErrorAsHandled();
     } 
   };
 }
 
 private IEnumerable<INotifyCompleted> SampleActions2(String country) {

   // Start a query for all customers in specified country, yield when async op completes.
   var op1 = _em1.Customers.Where(c => c.Country == country).ExecuteAsync();
   yield return op1;

   // Resume execution here when op1 completes.  Take a look at results from 1st query
   TraceFns.WriteLine("Customer count = " + op1.Results.Count().ToString());

   // Perform another async quuery for all employees.
   var op2 = _em1.Employees.ExecuteAsync();
   yield return op2;

   // Resume execution here when op2 completes.  See what it returned.
   TraceFns.WriteLine("Employee count = " + op2.Results.Count().ToString());
 }

Remarks

Used to start serial execution of the asynchronous, and synchronous, actions within the specified iterator block. Asychronous actions within the block will cause subsequent actions to "wait" until each asynchronous operation yields when complete.

See the second example below for how to pass arguments into the iterator.

Requirements

Target Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family

See Also

© 2013 All Rights Reserved.